const net = require("net");
const HOST = "127.0.0.1";
const PORT = 6868;

const client = new net.Socket();

client.connect(PORT, HOST, () => {
    console.log(`connected to:${HOST}:${PORT}`);
    // 向服务端发送数据
    client.write("客：你好服务端");
    // 收到服务端数据时
    client.on("data", (data) => {
        console.log(data.toString());
        client.write("客：已收到");
        // client.end(); // 主动关闭此次tcp长连接
    });
    // 客户端主动断连，触发自己的end事件
    client.on("end", () => {
        console.log("链接已主动断开");
    });
});

